<?php
if (isset($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
    die('Please do not load this page directly. Thanks!');
    
global $post;
?>
<?php
if (comments_open()) :
?>
<div class="mdui-panel-item mdui-panel-item-open">
    <div class="mdui-panel-item-header">
        发表评论<i class="line"></i>
    </div>
    <div class="mdui-panel-item-body" id="comment-wrap">
        <!-- Comment Form -->
        <form id="commentform" name="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post">
            <?php if (!is_user_logged_in()) : ?>
            <div class="mdui-textfield mdui-textfield-floating-label">
                <i class="mdui-icon material-icons">account_circle</i>
                <label class="mdui-textfield-label">昵称</label>
                <input class="mdui-textfield-input"  name="author" id="name" value="<?php echo $comment_author; ?>" />
            </div>
            <div class="mdui-textfield mdui-textfield-floating-label">
                <i class="mdui-icon material-icons">email</i>
                <label class="mdui-textfield-label">电子邮件</label>
                <input class="mdui-textfield-input" name="email" id="email" type="email" value="<?php echo $comment_author_email; ?>" />
            </div>
            <div class="mdui-textfield mdui-textfield-floating-label">
                <i class="mdui-icon material-icons">email</i>
                <label class="mdui-textfield-label">网址(选填)</label>
                <input class="mdui-textfield-input" name="url" id="url" value="<?php echo $comment_author_url; ?>" />
            </div>
            <?php else : ?>
            <div class="tip info">
                您已登录:<a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php">
                    <?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="退出登录">退出 &raquo;</a>
            </div>
            <?php endif; ?>
            <textarea name="comment" id="message">
                留下一个脚印!
            </textarea>
            <div id="slideVerify"></div>
            <button type="button" class="mdui-btn  mdui-btn-raised" id="submit-comment" onclick="checkForm();"> 立即提交</button>
            <button type="reset" class="mdui-btn  mdui-btn-raised">重置</button>
            <?php comment_id_fields(); ?>
            <?php do_action('comment_form', $post->ID); ?>
            <script type="text/javascript">
                ClassicEditor
                    .create( document.querySelector( '#message' ),
                    {
                        removePlugins: [ 'Heading' ],
                    })
                    .then( editor => {
                        e=editor;
                    } );
                function checkForm()
                {
                    $('#slideVerify').slideVerify({
                        type : 1,     //类型
                        vOffset : 5,   //误差量，根据需求自行调整
                        barSize : {
                            width : '100%',
                            height : '40px',
                        },
                        success : function() {
                            log('slideVerify OK');
                            $("#commentform").submit();
                        },             
                    });
                }
            </script>
        </form>
    </div>
</div>
<?php endif; ?>
<div class="mdui-panel-item mdui-panel-item-open">
    <div class="mdui-panel-item-header">
        <i class="mdui-icon material-icons">&#xe0b9;</i> 评论区<small>(
            <?php
        echo wp_count_comments(get_the_ID())->total_comments;
        ?>)</small><i class="line"></i>
    </div>
    <?php
    if (!empty($post->post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {
        ?>
    <div class="layui-card-body" id="comment">
        <p>
            <div class="mdui-panel-item-body">
                请输入密码查看评论内容!
            </div>
        </p>
    </div>
</div>
<?php
} else if (!comments_open()) {
    ?>
<div class="mdui-panel-item-body" id="comment">
    <p>
        <div class="tip info">
            评论功能已经关闭!
        </div>
    </p>
</div>
</div>
<?php wp_list_comments('type=comment&callback=comment_list'); ?>
<?php
} else if (!have_comments()) {
?>
<div class="mdui-panel-item-body" id="comment">
    <p>
        <div class="tip info">
            还没有任何评论，你来说两句吧!
        </div>
    </p>
</div>
</div>
<?php
} else {
?>
<div class="mdui-panel-item-body" id="comment">
    <?php
wp_list_comments('type=comment&callback=comment_list');
?>
</div>
</div>
<?php
}
?>